import { ref, onMounted, onUnmounted } from 'vue';

export function useNavHeight() {
  const navHeight = ref(0);

  const calculateNavHeight = () => {
    const systemInfo = uni.getSystemInfoSync();
    navHeight.value = systemInfo.statusBarHeight + 44; // 44 是导航栏的高度
  };

  onMounted(() => {
    calculateNavHeight();
   // 监听窗口大小变化事件
   uni.onWindowResize(calculateNavHeight);
  });

  onUnmounted(() => {
     // 移除窗口大小变化事件监听
     uni.offWindowResize(calculateNavHeight);
  });

  return {
    navHeight,
  };
}
